package cn.com.qingz.modules.user.controller;
import java.util.HashMap;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import cn.com.qingz.core.constantes.SystemConstantes;
import com.github.miemiedev.mybatis.paginator.domain.PageList;
import cn.com.qingz.core.model.DefaultResp;
import cn.com.qingz.modules.user.vo.*;
import cn.com.qingz.modules.user.service.*;
import cn.com.qingz.modules.user.model.*;
import cn.com.qingz.core.exception.DicmfException;


/**
 * @author codeGen
 */
@Controller
@RequestMapping("housemodel/*")
public class HouseModelController {

	@Resource
	private HouseModelService  housemodelService;

	/**
	 * 保存户型
	 * @param  
	 * @return
	 */
	@RequestMapping("save")
	@ResponseBody
	public DefaultResp<String> save(HouseModel   entity ){
		 DefaultResp<String>  res = new  DefaultResp<String>();
		 try {
			  housemodelService.doAddOrUpdate( entity);
		 } catch (org.springframework.dao.DuplicateKeyException e) {
			 throw new DicmfException(SystemConstantes.ERROR, "户型编码已经存在");
		 }
	     return res; 
	}

	/**
	 * 分页查询
	 * @param condition
	 * @param
	 * @param page 页码
	 * @return rows 每页行数
	 */
	@RequestMapping("queryForPage")
	@ResponseBody
	public Map<String,Object> queryByPage(HouseModelSearchCondition  condition,@RequestParam(required = false,defaultValue = "0") int page,
										    @RequestParam(required = false,defaultValue = "10") int rows){
		 PageList<?>  list =  housemodelService.queryForPage(condition, page, rows);
		 Map<String,Object>  res = new HashMap<String,Object>();
		 res.put("total", list.getPaginator().getTotalCount());
		 res.put("rows", list);
		 return res;
	}


	@RequestMapping("delete")
	@ResponseBody
	public DefaultResp<String> delete(Integer houseModelId) {
		DefaultResp<String> res = new DefaultResp<String>();
		housemodelService.doDelById(houseModelId);
		return res;
	}

}